﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.ComponentModel.DataAnnotations;
using System.Web.Mvc;
using DddCms.Application.Dto;
using AutoMapper;

namespace DddCms.Presentation.Areas.DddCms.Models.UserViewModel
{
    public class RegisterModel
    {
        [Required(ErrorMessage = "Le nom utilisateur est obligatoire")]
        [Display(Name = "Nom utilisateur")]
        [Remote("AlreadyExiste", "User", ErrorMessage = "Le nom utilisateur existe déjà.")]
        public string UserName { get; set; }

        [Required(ErrorMessage = "Le mot de passe est obligatoire")]
        [UIHint("Password")]
        [Display(Name = "Mot de passe")]
        public string Password { get; set; }

        [UIHint("Password")]
        [Compare("Password", ErrorMessage = "La confirmation n'est pas bonne.")]
        [Display(Name = "Confirmation")]
        public string ConfirmPassword { get; set; }

        [Required(ErrorMessage = "L'email est obligatoire")]
        public string Email { get; set; }

        [Display(Name = "Question")]
        [Required(ErrorMessage = "La question est obligatoire")]
        public string PasswordQuestion { get; set; }

        [Display(Name = "Réponse")]
        [Required(ErrorMessage = "La réponse à la question est obligatoire")]
        public string PasswordAnswer { get; set; }

        public UserDto ToUserDto()
        {
            Mapper.CreateMap<RegisterModel, UserDto>();
            return Mapper.Map<RegisterModel, UserDto>(this);
        }
    }
}